package com.zzyl.controller.manager;

import com.zzyl.base.PageBean;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.dto.NursingLevelPageQueryDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级管理")
@Slf4j
public class NursingLevelController {

    @Autowired
    private NursingLevelService nursingLevelService;

    @ApiOperation("分页查询护理等级信息")
    @GetMapping("listByPage")
    public ResponseResult<PageBean> pageQuery(NursingLevelPageQueryDto dto){
        log.info("分页条件查询护理等级");
        PageBean<NursingLevelVo> pageBean = nursingLevelService.pageQuery(dto);
        return ResponseResult.success(pageBean);
    }

    @ApiOperation("新增护理等级信息")
    @PostMapping("insert")
    public ResponseResult<Void> addNursingLevel(@RequestBody NursingLevelDto dto) {
        log.info("插入护理等级：{}", dto);
        nursingLevelService.addNursingLevel(dto);
        return ResponseResult.success();
    }



    @ApiOperation("根据ID查询护理等级信息")
    @GetMapping("{id}")
    public ResponseResult<NursingLevelVo> getNursingLevelById(@PathVariable Long id){
        log.info("查询护理等级：{}", id);
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return ResponseResult.success(nursingLevelVo);
    }




    @ApiOperation("更新护理等级信息")
    @PutMapping("update")
    public ResponseResult<Void> updateNursingLevel(@RequestBody NursingLevelDto dto){

        nursingLevelService.updateNursingLevel(dto);

        return ResponseResult.success();
    }


    @ApiOperation("删除护理等级信息")
    @DeleteMapping("delete/{id}")
    public ResponseResult<Void> deleteNursingLevel(@PathVariable Long id){

        nursingLevelService.deleteNursingLevel(id);
        return ResponseResult.success();
    }




    @ApiOperation("启用、禁用护理等级")
    @PutMapping("{id}/status/{status}")
    public ResponseResult<Void> enableOrDisable(@PathVariable Long id,
                                                @PathVariable Integer status){

        nursingLevelService.update(id, status);
        return ResponseResult.success();
    }

    @ApiOperation("查询所有护理等级信息")
    @GetMapping("listAll")
    public ResponseResult<List<NursingLevelVo>> selectAll(){
        List<NursingLevelVo> nursingLevelVos = nursingLevelService.list();
        return ResponseResult.success(nursingLevelVos);
    }
}